#!/usr/bin/env python
import xmpp, sys, time

def sendtwitter(alarm_id, timestamp, prefix_dec, new_homeas, old_homeas, bad_path):
  login = 'thu.argus'
  pwd = 'cnpttestcnpt'
  cnx = xmpp.Client('gmail.com')
  cnx.connect()
  cnx.auth(login, pwd, 'botty')
  if new_homeas != "0":
    alarm_str = "%s(UTC) #Argus: %s (Origin AS%s) MAY be hijacked by suspicious origin AS%s http://argus.csnet1.cs.tsinghua.edu.cn/fingerprints/%s/" % ( time.strftime("%b-%d %T", time.gmtime(int(timestamp))), prefix_dec, old_homeas, new_homeas, alarm_id)
  else:
    alarm_str = "%s(UTC) #Argus: %s MAY be hijacked by suspicious AS path segment '%s' http://argus.csnet1.cs.tsinghua.edu.cn/fingerprints/%s/" % ( time.strftime("%b-%d %T", time.gmtime(int(timestamp))), prefix_dec, bad_path, alarm_id)
  msg = xmpp.Message( 'sharangxy@twitter.tweet.im', alarm_str )
  #msg = xmpp.Message( 'sharangxy@gmail.com', alarm_str )
  cnx.sendInitPresence()
  cnx.send( msg )
  print >> sys.stderr, 'Send twitter success:', alarm_str
  time.sleep( 60 )

sendtwitter(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6])

